package com.tdf.webblog.service.serviceImpl;

import com.tdf.webblog.dao.AdminPermissionDAO;
import com.tdf.webblog.entity.AdminPermission;
import com.tdf.webblog.entity.AdminRolePermission;
import com.tdf.webblog.service.AdminPermissionService;
import com.tdf.webblog.service.AdminRolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class AdminPermissionServiceImpl implements AdminPermissionService {

    @Autowired
    private AdminRolePermissionService adminRolePermissionService;

    @Autowired
    private AdminPermissionDAO adminPermissionDAO;

    @Override
    public List<AdminPermission> listPermsByRoleId(int rid) {

        List<Integer> pids = adminRolePermissionService.findAllByRid(rid)
                .stream().map(AdminRolePermission::getPid).collect(Collectors.toList());
        return adminPermissionDAO.findAllById(pids);


    }
}
